package com.ray.friendslist.content.provider;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.net.Uri;
import android.util.Log;

import com.ray.friendslist.content.contract.FriendsContract;
import com.ray.friendslist.content.provider.common.CommonProvider;
import com.ray.friendslist.feeds.FeedEntyty;

public class FeedProvider extends CommonProvider {

	@Override
	public String getTableName() {
		return FriendsContract.VKFeedColoumns.TABLE_NAME;
	}

	@Override
	public ContentValues getContentValues(JSONObject jsonObject)
			throws JSONException {
		ContentValues values = new ContentValues();
		FeedEntyty feedEntyty = new FeedEntyty(jsonObject);
		Log.i("ray", "CONTENT VALUES --- "+ feedEntyty.getString("date"));
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[0],
				feedEntyty.getID());
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[1],
				jsonObject.getString("source_id"));
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[2],
				jsonObject.getString("type"));
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[3],
				feedEntyty.getFeedDate());
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[4],
				feedEntyty.getString("date"));
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[5],
				feedEntyty.getFeedText());
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[6],
				feedEntyty.getFeedName());
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[7],
				feedEntyty.getString("photo"));
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[8],
				feedEntyty.getFeedAttachments());
		values.put(FriendsContract.VKFeedColoumns.COLOUMNS[9],
				feedEntyty.getFeedLikes());
		return values;
	}

	@Override
	public String getContentType() {
		return FriendsContract.VKFeedColoumns.CONTENT_TYPE;
	}

	public String[] getColoumns() {
		return FriendsContract.VKFeedColoumns.COLOUMNS;
	}

	@Override
	protected String getOrderBy() {
		return FriendsContract.VKFeedColoumns.UNCONVERTED_DATE + " DESC";
	}

	@Override
	protected Uri getContentURI() {
		return FriendsContract.VKFeedColoumns.CONTENT_URI;
	}

}
